import { createRouter, createWebHistory } from 'vue-router'
import Layout from "@/layout/Layout.vue";
import store from '@/store'
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    meta:{
      requireAuth:true
    },
    redirect:"/work_bench",
    children:[
      {
        path: '/work_bench',
        name: '/work_bench',
        component: ()=>import("../views/systemManage/WorkBench")
      },
      {
        path: 'user',
        name: 'User',
        component: ()=>import("../views/systemManage/User")
      },
      {
        path:'person_detail',
        name:'person_detail',
        component:()=>import("../views/personManage/PersonDetail")
      },
      {
        path:'change_pwd',
        name:'change_pwd',
        component:()=>import("../views/personManage/PasswordChange")
      },
      {
        path:'goods',
        name:'goods',
        component:()=>import("../views/systemManage/Goods")
      },
      {
        path:'news',
        name:'News',
        component:()=>import("../views/News")
      },
      {
        path:'wait_order',
        name:'wait_order',
        component:()=>import("@/views/systemManage/orderManage/WaitOrder")
      },
      {
        path:'return_order',
        name:'return_order',
        component:()=>import("@/views/systemManage/orderManage/ReturnOrder")
      },
      {
        path:'ts_order',
        name:'ts_order',
        component:()=>import("@/views/systemManage/orderManage/TSOrder")
      },
      {
        path:'dispatch_order',
        name:'dispatch_order',
        component:()=>import("@/views/systemManage/orderManage/DispatchOrder")
      },
      {
        path:'receive_order',
        name:'receive_order',
        component:()=>import("@/views/systemManage/orderManage/ReceiveOrder")
      },

      {
        path:'purchasing_manage',
        name:'purchasing_manage',
        component:()=>import("@/views/systemManage/inventoryManage/PurchasingManagement")
      },
      {
        path:'store_analysis',
        name:'store_analysis',
        component:()=>import("@/views/systemManage/inventoryManage/StoreAnalysis")
      },
      {
        path:'sale_manage',
        name:'sale_manage',
        component:()=>import("@/views/systemManage/MoneyManage/SaleManage")
      },
      {
        path:'pay_manage',
        name:'pay_manage',
        component:()=>import("@/views/systemManage/MoneyManage/PayManage")
      },
    ]
  }
  ,
  {
    path: '/Login',
    name: 'Login',
    component: ()=>import("@/views/Login")
  },
  {
    path:"/mall",
    name:"mall",
    component: ()=>import("@/layout/mall-layout"),
    redirect: "/mall/goodsList",
    children: [
      {
        path:"/mall/goodsList",
        name:"/mall/goodsList",
        component:()=>import("@/views/mallSystem/GoodList")
      },
      {
        path:'/mall/person_detail',
        name: '/mall/person_detail',
        component:()=>import("@/views/mallSystem/PersonDetail")
      },
      {
        path:"/mall/change_pwd",
        name:'/mall/change_pwd',
        component:()=>import("@/views/personManage/PasswordChange")
      },
      {
        path: "/mall/cart",
        name:"/mall/cart",
        component:()=>import("@/views/mallSystem/Cart")
      },
      {
        path:"/mall/my_cart",
        name:"/mall/my_cart",
        component:()=>import("@/views/mallSystem/MyCart")
      },
      {
        path: "/mall/order_detail",
        name: "/mall/order_detail",
        component:()=>import("@/views/mallSystem/OrderDetail")
      },
      {
        path: "/mall/person_detail",
        name:"/mall/person_detail",
        component:()=>import("@/views/personManage/PersonDetail")
      }
    ]
  }

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
//调试阶段开启好难受
// router.beforeEach((to,from,next)=>{
//   if(to.meta.requireAuth){
//     if(store.state.userId){
//       next()
//     }else {
//       next({path:"/loin"})
//     }
//   }else {
//     next()
//   }
// })
